package com.yzkj.siot.controller;


import com.yzkj.siot.annotation.Permission;
import com.yzkj.siot.annotation.WebLog;
import com.yzkj.siot.base.BaseController;
import com.yzkj.siot.domain.TenantProduct;
import com.yzkj.siot.facade.ProductFacade;
import com.yzkj.siot.result.PageParams;
import com.yzkj.siot.result.PageResponse;
import com.yzkj.siot.type.ApiType;
import com.yzkj.siot.type.PermissionType;
import com.yzkj.siot.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 产品
 * 前端控制器
 * </p>
 *
 * @author skye
 * @since 2021-11-07
 */
@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {

    @Autowired
    ProductFacade facade;

    @WebLog(type = ApiType.DELETE)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("remove")
    public TenantProduct remove(@RequestParam int id) {
        return this.facade.remove(id);
    }

    @WebLog(type = ApiType.SAVE_OR_UPDATE)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("saveOrUpdate")
    public TenantProduct saveOrUpdate(@RequestBody TenantProduct entity) {
        return this.facade.saveOrUpdate(entity);
    }

    @WebLog(type = ApiType.READ)
    @Permission(type = PermissionType.TENANT)
    @GetMapping("queryOne")
    public ProductVO queryOne(@RequestParam int id) {
        return this.facade.queryOne(id);
    }

    @WebLog(type = ApiType.READ)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("page")
    public PageResponse<ProductVO> page(@RequestBody PageParams<TenantProduct> pageParams) {
        return this.facade.page(pageParams);
    }

    @WebLog(type = ApiType.DELETE)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("batchRemove")
    public Boolean batchRemove(@RequestBody List<Integer> idList) {
        return this.facade.batchRemove(idList);
    }
}

